package com.ljp.chat.support.enhancement;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ljp.chat.entity.Result;

import java.io.Serializable;

@SuppressWarnings("unused")
public interface RestCrudSupport<T, P extends Serializable>{
    /**
     * interface to get Result by pagination
     *
     * @param page pagination parameters
     * @return paginated Result
     */
    default Result<Object> getResultByPagination(Page<T> page) {
        return getResultByPagination(page, null);
    }

    /**
     * interface to get Result by pagination
     *
     * @param page  pagination parameters
     * @param query 用于查询的对象
     * @return paginated Result
     */
    default Result<Object> getResultByPagination(Page<T> page, T query) {
        return getResultByPagination(page, query, null);
    }

    /**
     * interface to get Result by pagination
     *
     * @param page   pagination parameters
     * @param filter 时间戳过滤对象
     * @param query  用于查询的对象
     * @return paginated Result
     */
    Result<Object> getResultByPagination(Page<T> page, T query, TimestampFilter filter);

    /**
     * delete Result based on primary key
     *
     * @param primaryKey primary key needs to be a subclass of serializable
     * @return success or failure
     */
    Result<Object> deleteById(P primaryKey);

    /**
     * get Result based on primary key
     *
     * @param primaryKey primary key needs to be a subclass of serializable
     * @return Result or failure
     */
    Result<Object> getById(P primaryKey);

    /**
     * update Result based on primary key
     *
     * @param entity primary key needs to be a subclass of serializable
     * @return success or failure
     */
    Result<Object> updateById(T entity);

    /**
     * save Result
     *
     * @param entity target
     * @return success or failure
     */
    Result<Object> save(T entity);

    /**
     * save Result or update Result
     *
     * @param entity target
     * @return success or failure
     */
    Result<Object> saveOrUpdate(T entity);
}
